<?php
if(
	isset( $_POST['username'] ) &&
	isset( $_POST['password'] ) 
)
{
	if( strlen( $_POST['username'] ) < 4 )
	{
		$feedback[] = ':-( The username have to be longer then 4 characters';
	}
	elseif( strlen( $_POST['password'] ) < 6 )
	{
		$feedback[] = ':-( The password have to be longer then 6 characters';
	}
	elseif( $_POST['password'] == $_POST['username'] )
	{
		$feedback[] = ':-( Sorry the password can not be the same as the username';
	}
	elseif ($_POST['scramblereg'] == $_SESSION['nonce'])
	{
		$feedback[] = ':-( Sorry but you entered the wrong confirmation code...';
	}
	else
	{
		include( 'library/dbconnect.php' );

		$username = mysql_real_escape_string( $_POST['username'] );
		$password = md5( $_POST['password'] );

		$sqlCheckForDuplicate = "SELECT u_id FROM tbl_users WHERE u_username = '". $username ."'";

		if( mysql_num_rows( mysql_query( $sqlCheckForDuplicate ) ) == 0 )
		{
			$sqlRegUser = 	"INSERT INTO
						tbl_users( u_username, u_password )
					VALUES(
						'". $username ."',
						'". $password ."'
						)";

			if( !mysql_query( $sqlRegUser ) )
			{
				$feedback[] = ':-( Seems like the database is offline. If this problem perists contact the support.';
			}
			else
			{
				$feedback[] = ':-) You can now login with your username and password';
				$formUsername = $username;
			}
		}
		else
		{
			$feedback[] = ':-( The username allready exists please try another one.';
			$formUsername = $username;
		}
	}
}
else
{
	$feedback[] = ':-( Sorry but you fail so totaly I, try again later perhaps...';
}
?>